package com.zlc.common.core.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zlc.common.common.service.BaseServiceImpl;
import com.zlc.common.core.process.model.entity.StoneEventConfig;
import com.zlc.common.core.process.model.entity.StoneProcessFormConfig;
import com.zlc.common.core.process.mapper.StoneProcessFormConfigMapper;
import com.zlc.common.core.process.model.vo.StoneProcessFormConfigVo;
import com.zlc.common.core.process.model.vo.StoneProcessVariableConfigVo;
import com.zlc.common.core.process.service.StoneProcessFormConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author  zl
 * @date 2023-10-18 
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class StoneProcessFormConfigServiceImpl extends BaseServiceImpl<StoneProcessFormConfigMapper, StoneProcessFormConfig, StoneProcessFormConfigVo> implements StoneProcessFormConfigService{
    @Override
    public void removeByProcessId(String processId) {
        LambdaQueryWrapper<StoneProcessFormConfig> wrapper = wrapper()
                .eq(StoneProcessFormConfig::getProcessId, processId);
        List<StoneProcessFormConfigVo> nodeVos = queryVoList(wrapper);
        if(!ObjectUtils.isEmpty(nodeVos)){
            List<String> ids = nodeVos.stream().map(StoneProcessFormConfigVo::getId).collect(Collectors.toList());
            deleteObjByIds(ids);
        }
    }

    @Override
    public List<StoneProcessFormConfigVo> getByProcessId(String processId) {
        LambdaQueryWrapper<StoneProcessFormConfig> wrapper = wrapper()
                .eq(StoneProcessFormConfig::getProcessId, processId);
        return queryVoList(wrapper);
    }

    @Override
    public List<StoneProcessFormConfigVo> getNodeForm(String processId, String nodeId) {
        LambdaQueryWrapper<StoneProcessFormConfig> wrapper = wrapper()
                .eq(StoneProcessFormConfig::getProcessId, processId)
                .eq(StoneProcessFormConfig::getNodeId, nodeId)
                .orderByAsc(StoneProcessFormConfig::getOrder);
        return queryVoList(wrapper);
    }
}
